From c642ec17d0d541835334b676e972539fdd5becdc Mon Sep 17 00:00:00 2001 From: "kaf24@localhost.localdomain" Date: Sun, 28 Jan 2007 19:02:00 +0000 Subject: [PATCH] Clean up libelf endian macros and includes. Based on a patch from John Levon Signed-off-by: Keir Fraser --- xen/common/libelf/libelf-private.h | 36 +++++++++++++++++------------- xen/common/libelf/libelf-tools.c | 4 ++-- xen/include/public/libelf.h | 33 +++++++-------------------- 3 files changed, 30 insertions(+), 43 deletions(-) diff --git a/xen/common/libelf/libelf-private.h b/xen/common/libelf/libelf-private.h index dfb47a06d4..4d9ef5ba4f 100644 --- a/xen/common/libelf/libelf-private.h +++ b/xen/common/libelf/libelf-private.h @@ -1,7 +1,13 @@ +#ifndef __LIBELF_PRIVATE_H__ +#define __LIBELF_PRIVATE_H_ + #ifdef __XEN__ +#include +#include #include #include +#include #include #include @@ -11,29 +17,25 @@ printk(fmt, ## args ) #define strtoull(str, end, base) simple_strtoull(str, end, base) -#define bswap_16(x) \ - ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)) -#define bswap_32(x) \ - ( (((x) & 0xff000000) >> 24) \ - | (((x) & 0x00ff0000) >> 8) \ - | (((x) & 0x0000ff00) << 8) \ - | (((x) & 0x000000ff) << 24)) -#define bswap_64(x) \ - ( (((x) & 0xff00000000000000ull) >> 56) \ - | (((x) & 0x00ff000000000000ull) >> 40) \ - | (((x) & 0x0000ff0000000000ull) >> 24) \ - | (((x) & 0x000000ff00000000ull) >> 8) \ - | (((x) & 0x00000000ff000000ull) << 8) \ - | (((x) & 0x0000000000ff0000ull) << 24) \ - | (((x) & 0x000000000000ff00ull) << 40) \ - | (((x) & 0x00000000000000ffull) << 56)) +#define bswap_16(x) swab16(x) +#define bswap_32(x) swab32(x) +#define bswap_64(x) swab64(x) #else /* !__XEN__ */ #include #include #include +#include +#include +#ifdef __sun__ +#include +#define bswap_16(x) BSWAP_16(x) +#define bswap_32(x) BSWAP_32(x) +#define bswap_64(x) BSWAP_64(x) +#else #include +#endif #include #include @@ -49,3 +51,5 @@ } while (0) #endif + +#endif /* __LIBELF_PRIVATE_H_ */ diff --git a/xen/common/libelf/libelf-tools.c b/xen/common/libelf/libelf-tools.c index c6a00c4dc6..a80fd8534d 100644 --- a/xen/common/libelf/libelf-tools.c +++ b/xen/common/libelf/libelf-tools.c @@ -7,7 +7,7 @@ /* ------------------------------------------------------------------------ */ uint64_t elf_access_unsigned(struct elf_binary * elf, const void *ptr, - off_t offset, size_t size) + uint64_t offset, size_t size) { int need_swap = elf_swap(elf); const uint8_t *u8; @@ -35,7 +35,7 @@ uint64_t elf_access_unsigned(struct elf_binary * elf, const void *ptr, } int64_t elf_access_signed(struct elf_binary *elf, const void *ptr, - off_t offset, size_t size) + uint64_t offset, size_t size) { int need_swap = elf_swap(elf); const int8_t *s8; diff --git a/xen/include/public/libelf.h b/xen/include/public/libelf.h index 888cede187..95fb1a2915 100644 --- a/xen/include/public/libelf.h +++ b/xen/include/public/libelf.h @@ -1,25 +1,12 @@ #ifndef __XC_LIBELF__ #define __XC_LIBELF__ 1 -#ifdef __XEN__ - -#include -#include -typedef uint64_t off_t; - -#define LITTLE_ENDIAN 1234 -#define BIG_ENDIAN 4321 #if defined(__i386__) || defined(__x86_64) || defined(__ia64__) -#define BYTE_ORDER LITTLE_ENDIAN +#define XEN_ELF_LITTLE_ENDIAN #elif defined(__powerpc__) -#define BYTE_ORDER BIG_ENDIAN -#endif - -#else /* !__XEN__ */ - -#include -#include - +#define XEN_ELF_BIG_ENDIAN +#else +#error define architectural endianness #endif #undef ELFSIZE @@ -91,14 +78,10 @@ struct elf_binary { /* ------------------------------------------------------------------------ */ /* accessing elf header fields */ -#if !defined(BYTE_ORDER) -# error BYTE_ORDER not defined -#elif BYTE_ORDER == BIG_ENDIAN +#ifdef XEN_ELF_BIG_ENDIAN # define NATIVE_ELFDATA ELFDATA2MSB -#elif BYTE_ORDER == LITTLE_ENDIAN -# define NATIVE_ELFDATA ELFDATA2LSB #else -# error BYTE_ORDER unknown +# define NATIVE_ELFDATA ELFDATA2LSB #endif #define elf_32bit(elf) (ELFCLASS32 == (elf)->class) @@ -131,9 +114,9 @@ struct elf_binary { : sizeof((str)->e32)) uint64_t elf_access_unsigned(struct elf_binary *elf, const void *ptr, - off_t offset, size_t size); + uint64_t offset, size_t size); int64_t elf_access_signed(struct elf_binary *elf, const void *ptr, - off_t offset, size_t size); + uint64_t offset, size_t size); uint64_t elf_round_up(struct elf_binary *elf, uint64_t addr); -- 2.30.2